Operation#
- class Operation(name=None, num_qubits=0, num_clbits=0, definition=None, params=[], init_op=None)[source]#
This class describes operations like quantum gates, measurements or classical logic gates. Operation objects do not carry information about which Qubit/Clbits they are applied to. This can be found in the Instruction class, which is a combination of an Operation object together with its operands.
Operation objects consist of five basic attributes:
.name
: A string identifying the operation.num_qubits
: An integer specifying the amount qubits on which to operate.num_clbits
: An integer specifying the amount of classical bits on which to operate..params
: A list of floats specifying the parameters of the Operation.definition
: A QuantumCircuit. For synthesized (i.e. non-elementary) operations, this QuantumCircuit specifies the operation.
Operation objects together with their Operands can be appended to QuantumCircuits by using the
append
method.QuantumCircuits can be turned into Operations by using the
to_gate
method.Examples
We create a QuantumCircuit and append a couple of operations
>>> from qrisp import QuantumCircuit, XGate, CXGate, PGate >>> qc = QuantumCircuit(2) >>> qc.append(XGate(), 0) >>> qc.append(CXGate(), [0,1]) >>> qc.append(PGate(0.5), 1) >>> synthed_op = qc.to_op() >>> qc.append(synthed_op, qc.qubits)
Methods#
Returns a copy of the Operation object. |
|
|
Returns the unitary matrix (if applicable) of the Operation as a numpy array. |
Returns the inverse of this Operation (if applicable). |
|
|
Returns the controlled version of this Operation (if applicable). |
|
Binds abstract parameters to specified values. |